<template>
  <div class="app-container">
    <!--    <el-form :model="queryParams" ref="queryRef" v-show="showSearch" :inline="true" label-width="68px">-->

    <!--      <el-form-item label="赛项名称" prop="roleName">-->
    <!--        <el-input v-model="queryParams.roleName" placeholder="请输入赛项名称" clearable style="width: 240px"-->
    <!--                  @keyup.enter="handleQuery"/>-->
    <!--      </el-form-item>-->
    <!--      <el-form-item label="赛事名称" prop="roleKey">-->
    <!--        <el-input v-model="queryParams.roleKey" placeholder="请输入赛事名称" clearable style="width: 240px"-->
    <!--                  @keyup.enter="handleQuery"/>-->
    <!--      </el-form-item>-->
    <!--      <el-form-item label="状态" prop="status">-->
    <!--        <el-select v-model="queryParams.status" placeholder="状态" clearable style="width: 240px">-->
    <!--          <el-option v-for="dict in sys_declare_type" :key="dict.value" :label="dict.label" :value="dict.value"/>-->
    <!--        </el-select>-->
    <!--      </el-form-item>-->
    <!--      <el-form-item>-->
    <!--        <el-button type="primary" icon="Search" @click="handleQuery">搜索</el-button>-->
    <!--        <el-button icon="Refresh" @click="resetQuery">重置</el-button>-->
    <!--      </el-form-item>-->
    <!--    </el-form>-->
    <!-- 表格数据 -->
    <el-table v-loading="loading" :data="dataList">
      <el-table-column type="selection" width="55" align="center"/>
      <el-table-column label="申请编号" prop="id" width="80"/>
      <el-table-column label="赛项名称" prop="competitionName" :show-overflow-tooltip="true" align="center"/>
      <el-table-column label="赛事名称" prop="eventName" :show-overflow-tooltip="true" align="center"/>
      <el-table-column label="主办方" prop="organizers" width="100" align="center"/>
      <el-table-column label="比赛方式" prop="raceType" width="100" align="center"/>
      <el-table-column label="赛道" prop="track" align="center" min-width="120"/>
      <el-table-column label="状态" prop="stageCurrentStatus" width="100" align="center">
        <template #default="scope">
          <dict-tag :options="sys_declare_type" :value="scope.row.stageCurrentStatus"/>
        </template>
      </el-table-column>
      <el-table-column label="创建时间" align="center" prop="createTime">
        <template #default="scope">
          <span>{{ parseTime(scope.row.createTime) }}</span>
        </template>
      </el-table-column>
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width" fixed="right" width="100">
        <template #default="scope">
          <el-tooltip content="查看" placement="top">
            <el-button link type="primary" icon="Upload" @click="handleSelect(scope.row)"
            >查看
            </el-button>
          </el-tooltip>
        </template>
      </el-table-column>
    </el-table>

    <pagination v-show="total > 0" :total="total" v-model:page="queryParams.pageNo"
                v-model:limit="queryParams.pageSize" @pagination="getList"/>
    <!-- 查看竞赛信息对话框 -->
    <el-dialog :title="title" v-model="open" width="1500px" append-to-body>
      <el-form ref="Ref" :model="form" rules="rules" label-width="200px" disabled>
        <el-row>
          <el-col :span="6">
            <el-form-item label="赛项名称" prop="name">
              <el-input v-model="form.competitionName"/>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="赛事名称" prop="name">
              <el-input v-model="form.eventName"/>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="专业大类" prop="name">
              <el-input v-model="form.category"/>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="主办方" prop="name">
              <el-input v-model="form.organizers"/>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="负责部门" prop="name">
              <el-input v-model="form.deptCharge"/>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="比赛方式" prop="name">
              <el-input v-model="form.raceType"/>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="赛道" prop="name">
              <el-input v-model="form.track"/>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="文件" prop="name">
              <a href="www.baidu.com" @click="">下载</a>
            </el-form-item>
          </el-col>
        </el-row>
        <el-table :data="form.participants">
          <el-table-column align="center" label="姓名">
            <template #default="scope">
              <el-form-item :prop="'participants.' + scope.$index + '.nameStudent'" label-width="30">
                <el-input v-model="scope.row.nameStudent" placeholder="请输入姓名"/>
              </el-form-item>
            </template>
          </el-table-column>
          <el-table-column align="center" label="学号">
            <template #default="scope">
              <el-form-item :prop="'participants.' + scope.$index + '.numberId'" label-width="10">
                <el-input v-model="scope.row.numberId" placeholder="请输入学号"/>
              </el-form-item>
            </template>
          </el-table-column>
          <el-table-column align="center" label="专业">
            <template #default="scope">
              <el-form-item :prop="'participants.' + scope.$index + '.major'" label-width="10">
                <el-input v-model="scope.row.major" placeholder="请输入专业"/>
              </el-form-item>
            </template>
          </el-table-column>
          <el-table-column align="center" label="身份证">
            <template #default="scope">
              <el-form-item :prop="'participants.' + scope.$index + '.identityCard'" label-width="10">
                <el-input v-model="scope.row.identityCard" placeholder="请输入证件号"/>
              </el-form-item>
            </template>
          </el-table-column>
          <el-table-column align="center" label="联系方式">
            <template #default="scope">
              <el-form-item :prop="'participants.' + scope.$index + '.numberPhoneStudent'" label-width="10">
                <el-input v-model="scope.row.numberPhoneStudent" placeholder="请输入联系方式"/>
              </el-form-item>
            </template>
          </el-table-column>
          <el-table-column align="center" label="联系方式">
            <template #default="scope">
              <el-form-item :prop="'participants.' + scope.$index + '.numberPhoneTeacher'" label-width="10">
                <el-input v-model="scope.row.numberPhoneTeacher" placeholder="请输入联系方式"/>
              </el-form-item>
            </template>
          </el-table-column>
          <el-table-column label="指导老师信息" align="center" width="300">
            <template #default="scope">
              <el-row>
                <el-col :span="12">
                  <el-form-item :prop="'participants.' + scope.$index + '.deptName'" label-width="10">
                    <el-input v-model="scope.row.deptName" placeholder="指导老师部门"/>
                  </el-form-item>
                </el-col>
                <el-col :span="12">
                  <el-form-item :prop="'participants.' + scope.$index + '.nameTeacher'" label-width="10">
                    <el-input v-model="scope.row.nameTeacher" placeholder="指导老师姓名"/>
                  </el-form-item>
                </el-col>
              </el-row>
            </template>
          </el-table-column>
        </el-table>
      </el-form>
    </el-dialog>
  </div>
</template>

<script setup name="Mydeclare">
import {authedList, approById, staffAuth, getStaff} from '@/api/contestment/myappro'

const router = useRouter();
const {proxy} = getCurrentInstance();
const {sys_declare_type} = proxy.useDict("sys_declare_type");
const dataList = ref([]);
const open = ref(false);
const loading = ref(true);
const showSearch = ref(true);
const total = ref(0);
const title = ref("");

const data = reactive({
  form: {},
  queryParams: {
    pageNo: 1,
    pageSize: 10,
    stageCurrent:2,
    status: undefined
  },
  rules: {
    name :[{required: true, message: '请输入姓名', trigger: 'input' }],
  }
});

const {queryParams, form, rules} = toRefs(data);

/** 搜索按钮操作 */
function handleQuery() {
  queryParams.value.pageNo = 1;
  getList();
};

/** 重置按钮操作 */
function resetQuery() {
  proxy.resetForm("queryRef");
  handleQuery();
}

/** 获取列表数据*/
function getList() {
  loading.value = true
  authedList(proxy.addDateRange(queryParams.value)).then((res) => {
    loading.value = false
    total.value = res.data.total;
    dataList.value = res.data.result
  });
}

/** 取消按钮*/
function cancel() {
  open.value = false;
  reset();
}


/** 获取列表信息*/
function getrow() {

}

/** 重置新增表以及其他数据*/
function reset() {
  form.value = {
    id: undefined,
    eventsName: undefined,    // 赛项名称
    contestName: undefined,  // 赛事名称
    name: undefined,  // 姓名
    idCard: undefined,  // 身份证
    age: undefined,  // 年龄
    status: '1', // 0待申报 1申报成功 2申报中 3驳回
    participants: [{
      deptId: '',
      identityCard: '',
      major: '',
      nameStudent: '',
      nameTeacher:'',
      numberId:'',
      numberPhoneStudent:'',
      numBerPhoneTeacher:'',
    }]
  };
}

/** 人员信息填报*/
function handleSelect(row) {
  reset();
  Object.assign(form.value, {
    competitionName: row.competitionName,   // 赛项名称
    eventsName: row.eventName,              // 赛事名称
    category: row.category,                 // 专业大类
    organizers: row.organizers,             // 主办方
    deptCharge: row.deptCharge,             // 负责部门
    raceType: row.raceType,                 // 比赛方式
    track: row.track,                       // 比赛方式
  });
  getStaff(row.relation).then(response=>{
    form.value.participants = response.data.result.persons
  })
  title.value = "比赛信息"
  open.value = true;
}

/** 通过申请 */
function handlePass(row) {
  const data = {
    auditStatus: 2, // 通过
    id: row.id,
  }
  proxy.$modal.confirm('是否确定通过编号为"' + data.id + '"的数据项').then(function (result) {
    return staffAuth(data);
  }).then(() => {
    getList()
    proxy.$modal.msgSuccess("通过申请")
  }).catch(() => {
  })
}

/** 驳回申请 */
function handleReject(row) {
  const data = {
    auditStatus: 1, // 驳回
    id: row.id,
  }
  proxy.$modal.confirm(`是否确定驳回编号为${data.id}的数据项`).then(function (result) {
    return staffAuth(data);
  }).then(() => {
    getList()
    proxy.$modal.msgSuccess("成功驳回")
  }).catch(() => {
  })

}

getList()
</script>

